package com.example.photography.adapter.product;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.CourseBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyCourseAdapter extends MyBaseAdapter {
    private boolean sign;

    public MyCourseAdapter(List list, Context context, boolean sign) {
        super(list, context);
        this.sign = sign;
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_course, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //根据位置装载数据
        CourseBean.CourseListBean courseBean = (CourseBean.CourseListBean) list.get(position);
        viewHolder.svCover.setImageURI(courseBean.getCover());
        viewHolder.tvTitle.setText(courseBean.getTitle());
        viewHolder.tvCourse.setText("共" + courseBean.getCourse_num() + "节");
        viewHolder.tvPeople.setText(courseBean.getPeople_num() + "次学习");
        if (sign) {//课程已购买
            viewHolder.tvPrice.setVisibility(View.GONE);
        }else {
            viewHolder.tvPrice.setVisibility(View.VISIBLE);
            viewHolder.tvPrice.setText(courseBean.getPrice());
        }
        return convertView;
    }


    static
    class ViewHolder {
        @BindView(R.id.sv_cover)
        SimpleDraweeView svCover;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_course)
        TextView tvCourse;
        @BindView(R.id.tv_people)
        TextView tvPeople;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.ll_item)
        LinearLayout llItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
